package org.wevil.thread;

import java.util.HashMap;
import java.util.Map;

/**
 * 线程工具类
 *
 * @author wanglei
 * @since 2021/1/8
 */
public class ThreadUtils {

    public static Map<String, Long> rtuThreadMap = new HashMap<>();
    public static Map<Long, Thread> rtuSendThreadMap = new HashMap<>();

    /**
     * 设置rtu设备名称和线程关联关系
     *
     * @author wanglei
     * @since 2021/1/8
     */
    public static void setRtuThreadMap(String deviceCode, Long threadId) {
        rtuThreadMap.put(deviceCode, threadId);
    }

    /**
     * 获取rtu设备名称和线程关联关系
     *
     * @author wanglei
     * @since 2021/1/8
     */
    public static Long getThreadName(String deviceCode) {
        return rtuThreadMap.get(deviceCode);
    }

    /**
     * 通过线程id获得线程
     *
     * @param threadId 线程id
     * @author wanglei
     * @since 2021/1/11
     */
    public static Thread getThreadById(long threadId) {
        return rtuSendThreadMap.get(threadId);
    }
}
